package com.kyhd.audio.util;

import java.io.InputStream;
import java.util.Date;

import com.aliyun.oss.OSSClient;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class UploadOSS {

	private static final String O = "/";
	
	/**
	 * 上传文件到到阿里云OSS服务器,自定义路径前缀
	 * @param prefixPath
	 * @param strdate
	 */
	public static String uploadCommon(InputStream inputStream, String prefix, String fileName,
			String endpoint, String accessKeyId, String accessKeySecret, String bucketName) {
//		log.info("OSS prefix:{},fileName:{},endpoint:{},accessKeyId:{},accessKeySecret:{},bucketName:{}",
//				prefix,fileName,endpoint,accessKeyId,accessKeySecret,bucketName);
		String path = null;
		if(!prefix.endsWith(O)) {
			prefix = prefix+O;
		}
		OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
		if (inputStream != null) {
			ossClient.putObject(bucketName, prefix + fileName, inputStream);
			path = prefix + fileName;
			log.info("novel upload audio:{}",path);
		}
		ossClient.shutdown();
		return path;
	}

}
